package binarySearchTree;

//二分法查找元素
public class Dichotomy {
    public static boolean find(int[] nums,int value){
        int left= 0;
        int right = nums.length - 1;
        int middle = 0;

        while(left <= right){
            middle = (left + right) / 2;
            if(nums[middle] == value){
                return true;
            } else if(value < nums[middle]) {
                //在左边找
                right = middle - 1;

            } else {
                left = middle + 1;

            }
        }
        return false;
    }

    public static void main(String[] args){
        int[] nums = {1,2,4,6,8,99};
        boolean have = find(nums,99);
        System.out.println(have);
    }
}
